import { Table, TableProps } from "antd";
import dayjs from "dayjs";
import React from "react";
import { User } from "./search-panel";
export interface Project {
  id: string;
  name: string;
  personId: string;
  pin: boolean;
  organization: string;
  created: number;
}
interface ListProps extends TableProps<Project> {
  users: User[];
}
export const List = ({ users, ...props }: ListProps) => {
  const columns = [
    {
      title: "名称",
      dataIndex: "name",
      key: "name",
      sorter: (a, b) => a.name.localeCompore(b.name),
    },
    {
      title: "部门",
      dataIndex: "organization",
      key: "organization",
      sorter: (a, b) => a.name.localeCompore(b.name),
    },
    {
      title: "负责人",
      render: (text, record) => (
        <span>
          {users.find((user) => user.id === record.personId)?.name || "未知"}
        </span>
      ),
    },
    {
      title: "创建时间",
      render: (value, project) => {
        return (
          <span>
            {project.created
              ? dayjs(project.created).format("YYYY-MM-DD")
              : "无"}
          </span>
        );
      },
    },
  ];
  return <Table columns={columns} pagination={false} {...props} />;
};
